package shy.mapper;

import org.apache.ibatis.annotations.*;
import shy.bean.User;

import java.util.List;

@Mapper
public interface UserMapper {
    //    获取所有用户信息的操作
    @Select("select u.*,floor(DATEDIFF(now(),birthday)/365) as userAge from wams_user u where state=0")
    List<User> findAllUser();
    //删除指定用户的操作：逻辑删除
    @Update("update wams_user set state=1 where id=#{id}")
    int deleteUserById(int id);
    @Select("select u.*,floor(DATEDIFF(now(),birthday)/365) as userAge from wams_user u " +
            "where state=0 and userName like #{userName} and userRole=#{userRole}")
    List<User> findUserByNameAndRole(@Param("userName") String userName,@Param("userRole") int userRole);
    @Insert("insert into wams_user(id,userCode,userName,userPassword,gender,birthday,phone,address,userRole,state)" +
            "values(null,#{userCode},#{userName},md5(#{userPassword}),#{gender},#{birthday},#{phone},#{address},#{userRole},0)")
    int saveUser(User user);

    @Update("update wams_user set userName=#{userName},gender=#{gender},birthday=#{birthday},address=#{address},phone=#{phone},userRole=#{userRole} where id=#{id}")
    int updateUser(User user);

    @Select("select * from wams_user where state=0 and userCode=#{userCode} and userPassword=md5(#{userPassword})")
    User login(@Param("userCode") String userCode,@Param(("userPassword")) String userPassword);

    @Update("update wams_user set userPassword=md5(#{password}) where id=#{id}")
    int updateUserPassword(@Param("id") int id,@Param("password") String password);

}



